package com.zws.cucumber.util.colorfullog.table;

import static com.zws.cucumber.util.colorfullog.ZwsColorfulLogHelper.cyan;
import static com.zws.cucumber.util.colorfullog.ZwsColorfulLogHelper.fill;

public class ZwsSequenceRender implements ZwsPrefixRender {
    private int maxSeq;
    private int len;
    private String empty;

    public ZwsSequenceRender(int maxSeq) {
        if (maxSeq == 0) {
            this.maxSeq = 0;
            this.len = 0;
            this.empty = "";
        } else {
            if (maxSeq < 10) {
                maxSeq = 99;
            }
            this.maxSeq = maxSeq;
            this.len = Integer.toString(maxSeq).length();
            this.empty = fill(' ', this.len);
        }
    }

    public String render() {
        return empty;
    }

    public String render(int seq) {
        if (len == 0) {
            return empty;
        }
        String seqStr = Integer.toString(seq);
        int seqLen = seqStr.length();
        int paddingLen = len - seqLen;
        if (paddingLen > 0) {
            return fill(' ', paddingLen) + cyan(seqStr);
        } else {
            return cyan(seqStr);
        }
    }
}
